﻿using Little.Soldier.SWIFT.Validation;
using System;
using System.Collections.Generic;

namespace Little.Soldier.SWIFT
{
    [Serializable]
    public abstract class SwiftValueBlock : SwiftBlockBase
    {
        public virtual bool IsEmpty
        {
          get
          {
            return this.GetValue() == null;
          }
        }

        public virtual int Size
        {
            get
            {
                switch (this.GetValue())
                {
                    case null:
                    return 0;
                    default:
                    return this.GetValue().Length;
                }
            }
        }

        public SwiftValueBlock(SwiftMessage swiftMessage)
          : base(swiftMessage)
        {
        }

        public virtual string GetValuePart(string value, int start, int size)
        {
            string str = (string) null;
            if (start < value.Length)
            {
                if (start + size >= value.Length)
                    size = value.Length - start;
                try
                {
                    str = value.Substring(start, size);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return str;
        }

        public abstract string GetValue();

        public abstract bool SetValue(string value, List<ValidationError> parseError);
  }
}
